package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"week-three/global"
	"week-three/internal/model/dao"
	"week-three/internal/model/service"
	"week-three/internal/pkg"
	"week-three/internal/request"
)

func Publisher(c *gin.Context) {

	//接受参数
	var Req request.About
	err := c.ShouldBind(&Req)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"message": "参数获取失败"})
		return
	}

	//入库
	add, err := service.Add(Req)
	if err != nil {
		return
	}
	//实例化rabbitmq
	simple := pkg.NewRabbitMQSimple("about")
	//消息生产到消息队列
	simple.PublishSimple(add)
	c.JSON(http.StatusOK, gin.H{"code": 200, "message": "成功", "data": add})
}
func FindAbout(c *gin.Context) {
	name := c.PostForm("name")
	var about []dao.About
	err := global.DB.Where("name = ?", name).Find(&about).Error
	if err != nil {
		return
	}
	c.JSON(http.StatusOK, gin.H{"code": 200, "message": "成功", "data": about})

}
